package com.zm.core.config;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.druid.DruidStatViewHandler;
import com.jfinal.render.ViewType;
import com.zm.core.controller.BuyerController;
import com.zm.core.controller.FrontController;
import com.zm.core.controller.IndexController;
import com.zm.core.controller.LogoController;
import com.zm.core.controller.MenuController;
import com.zm.core.controller.SellerAdminController;
import com.zm.core.controller.SellerController;
import com.zm.core.controller.SizeController;
import com.zm.core.controller.SystemController;
import com.zm.core.controller.TaobaoController;
import com.zm.core.controller.UseLogController;
import com.zm.core.controller.UserController;
import com.zm.core.interceptors.ExceptionIntoLogInterceptor;
import com.zm.core.model.Comment;
import com.zm.core.model.Logo;
import com.zm.core.model.Menu;
import com.zm.core.model.Product;
import com.zm.core.model.Seller;
import com.zm.core.model.Size;
import com.zm.core.model.Templet;
import com.zm.core.model.UseCare;
import com.zm.core.model.UseLog;
import com.zm.core.model.User;
import com.zm.core.model.Usize;

public class Config extends JFinalConfig {

	@Override
	public void configConstant(Constants constants) {
		loadPropertyFile("shoesize.properties");
		constants.setViewType(ViewType.FREE_MARKER);
		constants.setDevMode(true);
	}

	@Override
	public void configHandler(Handlers handlers) {
		handlers.add(new ContextPathHandler("base"));//添加项目contextPath,以便在页面直接获取该值 ${base?if_exists}
		DruidStatViewHandler druidStatViewHandler = new DruidStatViewHandler("/druid");
		handlers.add(druidStatViewHandler);
	}

	@Override
	public void configInterceptor(Interceptors interceptors) {
		interceptors.addGlobalServiceInterceptor(new ExceptionIntoLogInterceptor());
	}

	@Override
	public void configPlugin(Plugins plugins) {
//		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("username"), getProperty("password").trim());
//		plugins.add(c3p0Plugin);
//		
//		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
//		plugins.add(arp);

		DruidPlugin druidPlugin=new DruidPlugin(getProperty("jdbcUrl"), getProperty("username"), getProperty("password").trim());
		druidPlugin.addFilter(new StatFilter());
//		WallFilter wall = new WallFilter();
//		wall.setDbType("mysql");
//		druidPlugin.addFilter(wall);
//		druidPlugin.setMaxPoolPreparedStatementPerConnectionSize(2);
		druidPlugin.setInitialSize(10);
		druidPlugin.setMaxActive(50);
		plugins.add(druidPlugin);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
		plugins.add(arp);
		
		arp.addMapping("s_menu", Menu.class);
		arp.addMapping("d_logo", Logo.class);
		arp.addMapping("d_size", Size.class);
		arp.addMapping("u_seller", Seller.class);
		arp.addMapping("u_use_log", UseLog.class);
		arp.addMapping("u_use_care", UseCare.class);
		arp.addMapping("u_user", User.class);
		arp.addMapping("u_product", Product.class);
		arp.addMapping("u_templet", Templet.class);
		arp.addMapping("u_size", Usize.class);
		arp.addMapping("u_comment", Comment.class);
		
	}

	@Override
	public void configRoute(Routes routes) {
		routes.add("/index",IndexController.class,"/page/");
		routes.add("/system",SystemController.class,"/page/");
		routes.add("/menu",MenuController.class,"/page/");
		routes.add("/user",UserController.class,"/page/");
		routes.add("/logo",LogoController.class,"/page/");
		routes.add("/size",SizeController.class,"/page/");
		routes.add("/seller",SellerController.class,"/page/");
		routes.add("/uselog",UseLogController.class,"/page/");
		routes.add("/selleradmin",SellerAdminController.class,"/page/");
		routes.add("/taobao",TaobaoController.class,"/page/");
		routes.add("/buyer",BuyerController.class,"/page/");
		routes.add("/front",FrontController.class,"/page/");
	}


}
